<?php
	include_once("./global.php");
	session_start();
	if($_SESSION[id]){	
		if(isset($_POST['insert_app'])){
			if($_POST['app_overhead'] == '0'){
				$update = '0';
				$apppadid = '0';
			}else{
				$update = $_POST['app_overhead'];
				if(is_uploaded_file($_FILES['uploaded']['tmp_name'])){
					$uploaded = $_FILES["uploaded"];
					if($uploaded['error'] > 0){
						echo "<script>alert('上传出错，请重试')</script>";
					}else{
						if($uploaded["size"] <= '3145728'){
							$date = mktime();	
							$name = $_POST['uploaded_name'];
							$type = $_FILES['uploaded']['type'];
							$image_name = $name.$date;
							$path = "../images/";
							$file_pathname = "../images/".$name.".png";				
							if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$file_pathname)){
								$sql_insert_pic = "INSERT INTO pictureinfo(`P_PID`, `P_Name`, `P_ID`, `P_Path`, `P_Class`, `P_Adid`, `P_Adclass`, `P_Date`, `P_Url`) VALUES (NULL,'$name','$url_trackid','$path','2','1','$update','$date',NULL)";
								$query_insert_pic = $mysqli->query($sql_insert_pic);
								if($query_insert_pic){
									$sql_select_pid = "select P_PID from pictureinfo where P_Date = '$date'";
									$query_select_pid = $mysqli->query($sql_select_pid);
									$result_select_pid = $query_select_pid->fetch_assoc();
									if($result_select_pid){
										$A_Apppadid = $result_select_pid['P_PID'];
									}else{
										echo "<script>alert('图片查询失败')</script>";
									}
								}else{
									echo "<script>alert('图片添加失败')</script>";
									echo $mysqli->error.$url_trackid;
								}
							}else{
								echo "失败";
							}				
						}else{
							echo "<script>alert('图片太大')</script>";
						}
					}
				}else{
					echo "<script>alert('请选择你要上传的图片')</script>";
				}
			}
			$date = mktime();
			$sql = "INSERT INTO `appinfo`(`A_Appid`, `A_Class`, `A_Categoryid`, `A_Apptrackid`, `A_Apptrackname`, `A_Appdesc`, `A_Appkid`, `A_Appartistid`, `A_Appartistname`, `A_Appversion`, `A_Appicon`, `A_Appprice`, `A_Appfilesize`, `A_Appreleasedate`, `A_Apprating`, `A_Appcountratinguser`, `A_Applanguage`, `A_Appdownload`, `A_Appartworkurl`, `A_Appadid`, `A_Apppadid`, `A_Appstatus`, `A_Applike`, `A_Appdate`) VALUES (NULL,'$_POST[insert_class]','$_POST[insert_category]',NULL,'$_POST[insert_apptrackname]','$_POST[insert_desc]','$_POST[insert_keyword]','$_POST[insert_appartistid]','$_POST[insert_appartistname]','$_POST[insert_appversion]','$_POST[insert_appicon]','$_POST[insert_price]','$_POST[insert_appfilesizebytes]','$_POST[insert_appreleasedate]','$_POST[insert_apprating]','$_POST[insert_appcountratinguser]','$_POST[insert_applanguage]','$_POST[insert_appdownload]','$_POST[insert_appscreenshot]','$update','$apppadid','1','$_POST[insert_applike]','$date')";
			echo $sql;
			$query = $mysqli->query($sql);
			if($query){
				echo "111";
			}else{
				echo $mysqli->error;
			}
		}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<title>后台首页</title>
<style>
	body{ background:#e7e7e7; margin:0; padding:0;}
	#container{ width:980px; height:auto; position:relative; margin:0 auto;}
	#container #header{ width:980px; height:90px; position:relative; background:#000; line-height:90px;color:#fff; font-size:24px; text-align:center;}
	.left{width:250px; height:auto; position:relative; float:left;}
	.left table{width:248px; height:auto; position:relative; float:left; background:#fff;}
	.left table td{ height:20px; text-align:center;}
	.left table .selected{ background:#73abe3;}
	#content{ width:730px; height:100%; position:relative; float:left; margin:2px 0px;}
	#content .title{ width:720px; height:25px; position:relative; float:left; line-height:25px; font-size:18px; color:#fff; background:#000;}
	form{margin:20px auto; width:720px; height:auto; position:relative; float:left;}
	form .inpuarea{ width:360px; height:150px;}
</style>
</head>
<body>
	<div id="container">
		<div id="header">
			818苹果站后台管理
		</div>
		<div class="left">
			<table>
				<tr><td style="background:#000000; color:#fff;">站点管理</td></tr>
				<tr><td><a href="admin_site_mangerment.php">全局管理</a></td></tr>
				<tr><td>静态页面管理</td></tr>
				<tr><td><a href="admin_link_mangerment.php?page=1">友情链接管理</a></td></tr>
				<tr><td><a href="admin_member_mangerment.php?page=1">会员管理</a></td></tr>
				<tr><td><a href="admin_tags_mangerment.php?page=1">标签管理</a></td></tr>
				<tr><td><a href="admin_search_mangerment.php?page=1">搜索管理</a></td></tr>
			</table>
			<table>
				<tr><td style="background:#000000; color:#fff;">文章管理</td></tr>
				<tr><td><a href="admin_category_mangerment.php">文章分类管理</a></td></tr>
				<tr><td><a href="admin_news_add.php">发布文章</a></td></tr>
				<tr><td><a href="admin_news_mangerment.php?page=1">文章管理</a></td></tr>
			</table>
			<table>
				<tr><td style="background:#000000; color:#fff;">应用管理</td></tr>
				<tr><td><a href="admin_appcate_mangerment.php?page=1">应用分类管理</a></td></tr>
				<tr><td class="selected"><a href="admin_app_add.php">添加应用</a></td></tr>
				<tr><td><a href="admin_app_mangerment.php?page=1">应用管理</a></td></tr>
                <tr><td><a href="admin_app_collection.php">应用采集</a></td></tr>
				<tr><td><a href="admin_app_collection_single.php">单应用采集</a></td></tr>
			</table>
		</div>
	<div id="content">
		<div class="title">发布APP</div>
		<form action="" method="post" enctype="multipart/form-data">
		<table>
			<tr>
				<td><label>APP标题</label></td><td><input type="text" name="insert_apptrackid" value="<?php echo $result_select_detail['A_Apptrackid'];?>" /><input class="input" type="text" name="insert_apptrackname" size="50" value="<?php echo trim($result_select_detail['A_Apptrackname']);?>"/>(最大长度25个字)</td>
			</tr>
            <tr>
				<td><label>APP分类</label></td><td>
                <input type="radio" name="insert_class" value="0"/>IOS_APP<input type="radio" name="insert_class" value="1" />越狱APP
                </td>
			</tr>
            <tr><td>
			
				<label>APP类别</label></td><td>
			<?php
				$sql_select_category = "select * from appcategoryinfo";
				$query_select_category = $mysqli->query($sql_select_category);
				while($result_select_category = $query_select_category->fetch_assoc()){
/*					
				}
				$sql_select_category = "select * from appcategoryinfo";
				$query_select_category = $mysqli->query($sql_select_category);
				while($result_select_category = $query_select_category->fetch_assoc()){
					$categoryname = $result_select_category['AC_Categoryname'];
					$sql_select_kname = "select K_Name from keywordinfo where K_ID = '$categoryname'";
					$query_select_kname = $mysqli->query($sql_select_kname);
					$result_select_kname = $query_select_kname->fetch_assoc();*/
			?>
                <input type="radio" name="insert_category" size="50" value="<?php echo $result_select_category['AC_Categoryid']?>" /><?php echo $result_select_category['AC_Categoryname']?>
			<?
				}
			?></td>
			</tr>
			<tr>
				<td><label>APP关键词</label></td><td><input type="text" size="50" name="insert_keyword" value="" />(最大长度50个)</td> <td><input type="submit" name="check_keyword" value="关键词转换" /></td>
			</tr><td></td><td>
			<?php
            
				if(isset($_POST['check_keyword'])){
					$keyword = $_POST['insert_keyword'];
					$keyword_explode = explode(",",$keyword);
					$count = count($keyword_explode);
					for($i=0;$i<$count;$i++){
					$sql = "select * from keywordinfo where K_Name = '$keyword_explode[$i]'";
					$query = $mysqli->query($sql);
					$result = $query->fetch_assoc();
					if($result){
						$new = $result['K_KID'];
			?>
				<?php echo $new?>,
			<?php
            			}else{
							$sql = "INSERT INTO keywordinfo (K_KID, K_ID, K_Name) VALUES (NULL, NULL, '$keyword_explode[$i]')";
							$query = $mysqli->query($sql);
				
							$sql_select = "select K_KID from keywordinfo where K_Name = '$keyword_explode[$i]'";
							$query_select = $mysqli->query($sql_select);
							$result_select = $query_select->fetch_assoc();
			?>
				<?php echo $result_select['K_KID'];?>,
            <?php
						}
					}	
				}		
			?>
				</td><td></td>
			<tr>
			</tr>
			<tr>
				<td><label>APP价格</label></td>
                <td>
                    <input type="text" name="insert_price"  size="50" value="" />(精确到小数点后两位)</td>
			</tr>
            <tr>
            	<td><label>APP厂商ID</label></td>
                <td><input type="text" name="insert_appartistid" size="50" value="" />
                </td>
            </tr>
            <tr>
            	<td><label>APP厂商名称</label></td>
                <td><input type="text" size="50" name="insert_appartistname" value="" />
                </td>
            </tr>
            <tr>
            	<td><label>APP语言</label></td>
                <td><input type="text" size="50" name="insert_applanguage" value="" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP下载地址</label></td>
                <td><input type="text" size="50" name="insert_appdownload" value="" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP喜欢人数</label></td>
                <td><input type="text" size="50" name="insert_applike" value="" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP发布时间</label></td>
                <td><input type="text" size="50" name="insert_appreleasedate" value="" />
            	</td>
            </tr>
           	<tr>
            	<td><label>APP图标(60*60)</label></td>
                <td><input type="text" size="50" name="insert_appicon" value="" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP截图</label></td>
                <td><input size="50" name="insert_appscreenshot" value=""/></td>
            </tr>
            <tr>
            	<td><label>APP大小</label></td>
                <td><input type="text" size="50" name="insert_appfilesizebytes" value="" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP评分</label></td>
                <td><input type="text" size="50" name="insert_apprating" value="" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP评分人数</label></td>
                <td><input type="text" size="50" name="insert_appcountratinguser" value="" />
            	</td>
            </tr>
            <tr>
            	<td><label>APP版本号</label></td>
                <td><input type="text" size="50" name="insert_appversion" value="" />
                </td>
            </tr>
            <tr>
				<td><label>APP推送位置</label></td><td><input type="checkbox" name="app_overhead" value="0" />无推广<input type="checkbox" name="app_overhead" value="1" />幻灯1<input type="checkbox" name="app_overhead" value="2" />幻灯2<input type="checkbox" name="app_overhead" value="3" />幻灯3<input type="checkbox" name="app_overhead" value="4" />幻灯4<input type="checkbox" name="app_overhead" value="5" />幻灯5<input type="checkbox" name="app_overhead" value="6" />首页推广1<input type="checkbox" name="app_overhead" value="7" />首页推广2<input type="checkbox" name="app_overhead" value="8" />右侧推广1<input type="checkbox" name="app_overhead" value="9" />右侧推广2</td>
			</tr>
            <tr>
            	<td><label>配图</label></td><td><input type="file" name="uploaded" /><input type="text" name="uploaded_name" /></td>
            </tr>
			<tr>
				<td><label>APP描述</label></td><td><textarea class="inpuarea" name="insert_desc"  />
                <?php
                	print_r($_POST['insert_appdesc']);
				?>
                </textarea>(最大长度120个字)</td>
			</tr>
			<tr>
				<td><input type="submit" name="insert_app" value="提交" /></td>
			</tr>
		</table>
		</form>
        </table>
	</div>
</div>
</body>
</html>
<?php

	}else{
		echo "<script>alert('登录先')</script>";
		echo "<meta http-equiv=\"refresh\" content=\"1; url='admin_login.php' />";
	}

?>